import React from 'react';
import { connect } from 'dva';
import BaseInfo from '../../../Product/productManageNew/TabWrap/BaseInfo';
import { FirstHeaderC } from '../../../../comps';
import CardC from '../../Barra/comps/cardC';
import styles from './index.less';
class BaseInfoForm extends React.Component {
  constructor() {
    super();
    this.state = {
      formDatas: { baseInfo: { inveType: '1' } },
      modeType: '0',
    };
  }
  componentDidMount() {
    const {
      globalM: { dataDictionary = {} },
      dispatch,
      pageType,
      productId,
    } = this.props;
    dispatch({
      type: 'productManageM/fetchDictByKeys',
      payload: {
        dictData: dataDictionary,
      },
    });
    this.props.dispatch({
      type: 'productManageM/tradingInformationDrop',
      payload: {},
    });
    if (pageType != 'add') {
      dispatch({
        type: 'productManageM/getDetail',
        payload: {
          id: productId,
        },
        callback: (res) => {
          if (res) {
            this.setState({
              modeType: res?.baseInfo?.modetype,
              formDatas: {
                baseInfo: res?.baseInfo || {}, //基本信息
                temp: new Date().getTime(),
              },
            });
          }
        },
      });
    }
  }

  changeFormPage = (e) => {
    if (e == 'add') {
      this.props.addNewProduct();
    } else {
      this.props.changePage(1);
    }
  };

  render() {
    const { formDatas, modeType } = this.state;
    const { pageType } = this.props;
    return (
      <div className={styles.BaseInfoForm}>
        <CardC title='新增产品' type='back' showContent={true} titleIsShow={false} changeFormPage={(e) => this.changeFormPage(e)} />
        {/* 内容 */}
        <div className={styles.baseInfo}>
          <FirstHeaderC title='产品管理'></FirstHeaderC>
          <BaseInfo
            productId={this.props.productId}
            type={'workStation'}
            modeType={modeType}
            pageType={pageType}
            formDatas={formDatas} //将【投资类型】定位在“权益类”
            changeFormPage={(e) => this.changeFormPage(e)}
          ></BaseInfo>
        </div>
      </div>
    );
  }
}
export default connect(({ productManageM, globalM }) => ({ productManageM, globalM }))(BaseInfoForm);
